package com.blockchain.securewallet.utils;

import org.web3j.utils.Convert;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * Created by Chain-Cloud on 2018/5/30.
 */

public class ToMinUtitUtils {

    //比特币转换
    public static BigInteger btcConvertToMin(int unit,String value){

        BigDecimal result=new BigDecimal("0");

        if (unit == 0){
            result=new BigDecimal("100000000");
        }else if (unit == 3){
            result=new BigDecimal("1000");
        }else if (unit == 6){
            result=new BigDecimal("100");
        }else if (unit == 8){
            result=new BigDecimal("1");
        }else{
            result=new BigDecimal("100000000");
        }

        return new BigDecimal(value).multiply(result).toBigInteger();

    }

    //以太坊转换
    public static BigInteger ethConvertToMin(int unit,String value) {

        BigInteger result=new BigInteger("0");

        if (unit == 0){
            result= Convert.toWei(value, Convert.Unit.ETHER).toBigInteger();
        }else if (unit == 9){
            result=Convert.toWei(value, Convert.Unit.GWEI).toBigInteger();
        }else{
            result= Convert.toWei(value, Convert.Unit.ETHER).toBigInteger();
        }

        return result;
//        return new BigInteger(value).multiply(result);
    }
}
